home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / PowerPC / vbcc / Examples / contextswitch / pixeltest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-24  |  2.0 KB  |  90 lines

  1. /*
  2. ** pixeltest.c
  3. **
  4. ** determines the speed of context switches between PowerPC and M68k
  5. **
  6. ** Written by Frank Wille, March 98
  7. **
  8. */
  9.  
  10. #include <stdio.h>
  11.  
  12. #include <exec/types.h>
  13. #include <exec/libraries.h>
  14. #include <exec/memory.h>
  15. #include <dos/dos.h>
  16. #include <graphics/gfx.h>
  17. #include <graphics/gfxbase.h>
  18. #include <intuition/intuition.h>
  19.  
  20. #include <proto/exec.h>
  21. #include <proto/dos.h>
  22. #include <proto/graphics.h>
  23. #include <proto/intuition.h>
  24.  
  25.  
  26. #define WIDTH 128
  27. #define HEIGHT 80
  28.  
  29.  
  30. struct GfxBase *GfxBase = NULL;
  31. struct IntuitionBase *IntuitionBase = NULL;
  32.  
  33.  
  34.  
  35. main()
  36. {
  37.   static struct TagItem wintags[] = {
  38.     WA_Left,160,
  39.     WA_Top,100,
  40.     WA_Width,WIDTH,
  41.     WA_Height,HEIGHT,
  42.     WA_Borderless,TRUE,
  43.     WA_Activate,TRUE,
  44.     WA_RMBTrap,TRUE,
  45.     TAG_DONE,0
  46.   };
  47.   struct DateStamp ds1,ds2;
  48.   struct Window *win = NULL;
  49.   struct RastPort *rp;
  50.   int x,y;
  51.   double d;
  52.  
  53.   if (!(IntuitionBase = (struct IntuitionBase *)
  54.       OpenLibrary("intuition.library",36))) {
  55.     printf("no intuition.library!\n");
  56.     exit(20);
  57.   }
  58.   if (!(GfxBase = (struct GfxBase *)
  59.       OpenLibrary("graphics.library",36))) {
  60.     CloseLibrary((struct Library *)IntuitionBase);
  61.     printf("no graphics.library!\n");
  62.     exit(20);
  63.   }
  64.  
  65.   if (win = OpenWindowTagList(NULL,wintags)) {
  66.     rp = win->RPort;
  67.     DateStamp(&ds1);
  68.     for (y=0; y<HEIGHT; y++) {
  69.       for (x=0; x<WIDTH; x++) {
  70.         SetAPen(rp,x&3);
  71.         WritePixel(rp,x,y);
  72.       }
  73.     }
  74.     DateStamp(&ds2);
  75.     CloseWindow(win);
  76.  
  77.     d = ((double)(ds2.ds_Days-ds1.ds_Days)*24*60*60*TICKS_PER_SECOND +
  78.          (double)(ds2.ds_Minute-ds1.ds_Minute)*60*TICKS_PER_SECOND +
  79.          (double)(ds2.ds_Tick-ds1.ds_Tick)) / (double)TICKS_PER_SECOND;
  80.     printf("Wrote %d pixels in %f seconds.\n"
  81.            "Test program did %f context switches per second.\n",
  82.            WIDTH*HEIGHT,d,(WIDTH*HEIGHT*2.0)/d);
  83.   }
  84.   else
  85.     printf("Can't open test window!\n");
  86.  
  87.   CloseLibrary((struct Library *)GfxBase);
  88.   CloseLibrary((struct Library *)IntuitionBase);
  89. }
  90.